package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Controller
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/users")
    public String findByPage(ModelMap modelMap,
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum ,
            @RequestParam(value = "pageSize", required = false, defaultValue = "2")Integer pageSize){
        PageInfo<User> pageInfo = userService.findByPage(pageNum, pageSize);
        modelMap.put("data", pageInfo);
        return "forward:userPro.jsp";
    }


    @GetMapping("/user/{id}")
    public String findById(@PathVariable("id") Integer id, ModelMap modelMap){
        User user = userService.findById(id);
        System.out.println(user);
        modelMap.put("user", user);

        return "forward:/index.jsp";
    }

}
